Repository navigation
Conversation
App webhook deliveries used Date.now() as X-GitHub-Delivery, so two deliveries in the same millisecond shared an ID. Receivers that deduplicate by delivery ID, as GitHub recommends, then dropped the second event. GitHub sends a GUID; the emulator now does too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Br5cbz3i7Y5PaRdx3DUfXx
| "Content-Type": "application/json", | ||
| "X-GitHub-Event": event, | ||
| "X-GitHub-Delivery": String(Date.now()), | ||
| "X-GitHub-Delivery": crypto.randomUUID(), |
There was a problem hiding this comment.
🟠 Bare crypto global; import randomUUID instead.
--- a/packages/@emulators/github/src/index.ts
+++ b/packages/@emulators/github/src/index.ts
@@
-import { createHmac, generateKeyPair } from "crypto";
+import { createHmac, generateKeyPair, randomUUID } from "crypto";
@@
- "X-GitHub-Delivery": crypto.randomUUID(),
+ "X-GitHub-Delivery": randomUUID(),🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #13, packages/@emulators/github/src/index.ts:634):
Problem: Bare crypto global; import randomUUID instead
Detail: The new code calls `crypto.randomUUID()` via the ambient WebCrypto global, but this file already imports its crypto primitives by name (`import { createHmac, generateKeyPair } from "crypto"`, line 1). The bare `crypto` identifier is never imported, so the module only compiles/runs where the global exists: the WebCrypto global is only available by default on Node >= 19 (Node 18 needs --experimental-global-webcrypto) and `tsc` only resolves it with recent @types/node. The surrounding code establishes at most a Node 18+ baseline (it uses global `fetch` / `AbortSignal.timeout`), so on Node 18 runtimes every app-webhook dispatch in `deliverToAppWebhookUrls` would throw a ReferenceError, and even where it works the implicit global is inconsistent with the file's own named-import convention. Use the named export from the module already imported.
Suggested fix: Extend the existing import on line 1 and call it directly: `import { createHmac, generateKeyPair, randomUUID } from "crypto";` then `"X-GitHub-Delivery": randomUUID(),`.
Suggested patch:
--- a/packages/@emulators/github/src/index.ts
+++ b/packages/@emulators/github/src/index.ts
@@
-import { createHmac, generateKeyPair } from "crypto";
+import { createHmac, generateKeyPair, randomUUID } from "crypto";
@@
- "X-GitHub-Delivery": crypto.randomUUID(),
+ "X-GitHub-Delivery": randomUUID(),
Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters
The new code calls crypto.randomUUID() via the ambient WebCrypto global, but this file already imports its crypto primitives by name (import { createHmac, generateKeyPair } from "crypto", line 1). The bare crypto identifier is never imported, so the module only compiles/runs where the global exists: the WebCrypto global is only available by default on Node >= 19 (Node 18 needs --experimental-global-webcrypto) and tsc only resolves it with recent @types/node. The surrounding code establishes at most a Node 18+ baseline (it uses global fetch / AbortSignal.timeout), so on Node 18 runtimes every app-webhook dispatch in deliverToAppWebhookUrls would throw a ReferenceError, and even where it works the implicit global is inconsistent with the file's own named-import convention. Use the named export from the module already imported.
const headers: Record<string, string> = {
"Content-Type": "application/json",
"X-GitHub-Event": event,
"X-GitHub-Delivery": crypto.randomUUID(),
};
if (ghApp.webhook_secret) {
const hmac = createHmac("sha256", ghApp.webhook_secret).update(body).digest("hex");
Code reviewVerdict: Address the major findings before merging. · 🔴 0 · 🟠 1 · 🟡 0 · ⚪ 0 · 0/1 resolved
🤖 Fix all 1 open findings with your agent📋 Out-of-diff findings (1)
Reviewed 2 files · 0 inline · view all 1 findings ↗ · AI-generated — verify findings before acting · AI guidance and feedback aictrl · AI code review for fast-moving teams · aictrl.dev |
Dependencies (#12): - issue_dependencies_summary counts only related issues every reader of the issue can see (same repository or public), so the shared issue payload no longer reveals blockers in private repositories. - DELETE needs write on the blocked issue only, so an edge whose far end became unreadable can still be removed; a malformed id returns 400. - One findIssueForRepo helper for issue and dependency routes. Delivery IDs (#13): import randomUUID by name. Issue types (#14): formatIssueType lives in helpers.ts beside the issue serializer; a null issue_types seed means the defaults; the type resolver returns number | null. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Br5cbz3i7Y5PaRdx3DUfXx
Review response — PR 13Fixes are in Issues addressed (pushed to this stack)
Review claims verified false (no change needed)None. Not addressed hereNone. |
Summary
App webhook deliveries now send
crypto.randomUUID()asX-GitHub-Deliveryinstead ofString(Date.now()), so two deliveries in the same millisecond no longer share an ID (closes #10). This is the same change as the upstream PR vercel-labs#413; the next upstream sync brings it in either way.aictrl can then remove its build-time patch (
scripts/e2e/patch-github-emulator-delivery-id.mjs).Stacked on #12; retarget after #11 and #12 merge.
Verification
webhook-installation.test.tspinsDate.now()and expects two distinct GUIDs. It fails before the change and passes after.node:24-bookworm-slim, all of these pass: build,type-check,type-check:tsc, lint (0 errors), format, and all package tests (core 113, github 188, github-emulator 6).🤖 Generated with Claude Code
https://claude.ai/code/session_01Br5cbz3i7Y5PaRdx3DUfXx